<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="父id" prop="hId">
        <el-input
          v-model="queryParams.hId"
          placeholder="请输入父id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务id" prop="seqNo">
        <el-input
          v-model="queryParams.seqNo"
          placeholder="请输入业务id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="IC卡号" prop="icCard">
        <el-input
          v-model="queryParams.icCard"
          placeholder="请输入IC卡号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车牌号" prop="veNo">
        <el-input
          v-model="queryParams.veNo"
          placeholder="请输入车牌号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="运管编码" prop="transportId">
        <el-input
          v-model="queryParams.transportId"
          placeholder="请输入运管编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="箱号" prop="contaId">
        <el-input
          v-model="queryParams.contaId"
          placeholder="请输入箱号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="rfid" prop="rfid">
        <el-input
          v-model="queryParams.rfid"
          placeholder="请输入rfid"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="rfid" prop="veNoPosition">
        <el-input
          v-model="queryParams.veNoPosition"
          placeholder="请输入rfid"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请进出场" prop="iEType">
        <el-select v-model="queryParams.iEType" placeholder="请选择申请进出场" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="载重类型" prop="veCrossType">
        <el-select v-model="queryParams.veCrossType" placeholder="请选择载重类型" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="核销状态" prop="veBillStatus">
        <el-select v-model="queryParams.veBillStatus" placeholder="请选择核销状态" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="通道代码" prop="channelCode">
        <el-input
          v-model="queryParams.channelCode"
          placeholder="请输入通道代码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="通道名称" prop="channelName">
        <el-input
          v-model="queryParams.channelName"
          placeholder="请输入通道名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆自重" prop="veSelfWeight">
        <el-input
          v-model="queryParams.veSelfWeight"
          placeholder="请输入车辆自重"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="过磅称重" prop="crossWeight">
        <el-input
          v-model="queryParams.crossWeight"
          placeholder="请输入过磅称重"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:passGateRecordList:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:passGateRecordList:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:passGateRecordList:remove']"
        >删除</el-button>
      </el-col>
     <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['system:passGateRecordList:export']"
        >导出</el-button>
      </el-col>
      -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="passGateRecordListList" @selection-change="handleSelectionChange" @row-dblclick="showDetail"  stripe border>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="父id" align="center" prop="hId" />
      <el-table-column label="业务id" align="center" prop="seqNo" />
      <el-table-column label="IC卡号" align="center" prop="icCard" />
      <el-table-column label="车牌号" align="center" prop="veNo" />
      <el-table-column label="运管编码" align="center" prop="transportId" />
      <el-table-column label="箱号" align="center" prop="contaId" />
      <el-table-column label="rfid" align="center" prop="rfid" />
      <el-table-column label="rfid" align="center" prop="veNoPosition" />
      <el-table-column label="申请进出场" align="center" prop="iEType" />
      <el-table-column label="载重类型" align="center" prop="veCrossType" />
      <el-table-column label="核销状态" align="center" prop="veBillStatus" />
      <el-table-column label="通道代码" align="center" prop="channelCode" />
      <el-table-column label="通道名称" align="center" prop="channelName" />
      <el-table-column label="车辆自重" align="center" prop="veSelfWeight" />
      <el-table-column label="过磅称重" align="center" prop="crossWeight" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
           <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="showDetail(scope.row)"
            v-hasPermi="['system:passGateRecordList:query']"
          >详情</el-button>
          
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:passGateRecordList:edit']"
          >修改</el-button>
          
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:passGateRecordList:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改卡口补录列对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px"  :disabled="isViewDisabled">
          <el-row>  
       		<el-col :span="12">
		        <el-form-item label="父id" prop="hId">
		          <el-input v-model="form.hId" placeholder="请输入父id" />
		        </el-form-item>
       		</el-col>
       		<el-col :span="12">
		        <el-form-item label="业务id" prop="seqNo">
		          <el-input v-model="form.seqNo" placeholder="请输入业务id" />
		        </el-form-item>
       		</el-col>
	  </el-row>
         <el-row>
       		<el-col :span="12">
		        <el-form-item label="IC卡号" prop="icCard">
		          <el-input v-model="form.icCard" placeholder="请输入IC卡号" />
		        </el-form-item>
       		</el-col>
       		<el-col :span="12">
		        <el-form-item label="车牌号" prop="veNo">
		          <el-input v-model="form.veNo" placeholder="请输入车牌号" />
		        </el-form-item>
       		</el-col>
	  </el-row>
         <el-row>
       		<el-col :span="12">
		        <el-form-item label="运管编码" prop="transportId">
		          <el-input v-model="form.transportId" placeholder="请输入运管编码" />
		        </el-form-item>
       		</el-col>
       		<el-col :span="12">
		        <el-form-item label="箱号" prop="contaId">
		          <el-input v-model="form.contaId" placeholder="请输入箱号" />
		        </el-form-item>
       		</el-col>
	  </el-row>
         <el-row>
       		<el-col :span="12">
		        <el-form-item label="rfid" prop="rfid">
		          <el-input v-model="form.rfid" placeholder="请输入rfid" />
		        </el-form-item>
       		</el-col>
       		<el-col :span="12">
		        <el-form-item label="rfid" prop="veNoPosition">
		          <el-input v-model="form.veNoPosition" placeholder="请输入rfid" />
		        </el-form-item>
       		</el-col>
	  </el-row>
         <el-row>
       		<el-col :span="12">
		        <el-form-item label="申请进出场" prop="iEType">
		          <el-select v-model="form.iEType" placeholder="请选择申请进出场">
		            <el-option label="请选择字典生成" value="" />
		          </el-select>
		        </el-form-item>
       		</el-col>
       		<el-col :span="12">
		        <el-form-item label="载重类型" prop="veCrossType">
		          <el-select v-model="form.veCrossType" placeholder="请选择载重类型">
		            <el-option label="请选择字典生成" value="" />
		          </el-select>
		        </el-form-item>
       		</el-col>
	  </el-row>
         <el-row>
       		<el-col :span="12">
		        <el-form-item label="核销状态">
		          <el-radio-group v-model="form.veBillStatus">
		            <el-radio label="1">请选择字典生成</el-radio>
		          </el-radio-group>
		        </el-form-item>
       		</el-col>
       		<el-col :span="12">
		        <el-form-item label="通道代码" prop="channelCode">
		          <el-input v-model="form.channelCode" placeholder="请输入通道代码" />
		        </el-form-item>
       		</el-col>
	  </el-row>
         <el-row>
       		<el-col :span="12">
		        <el-form-item label="通道名称" prop="channelName">
		          <el-input v-model="form.channelName" placeholder="请输入通道名称" />
		        </el-form-item>
       		</el-col>
       		<el-col :span="12">
		        <el-form-item label="车辆自重" prop="veSelfWeight">
		          <el-input v-model="form.veSelfWeight" placeholder="请输入车辆自重" />
		        </el-form-item>
       		</el-col>
	  </el-row>
         <el-row>
       		<el-col :span="12">
		        <el-form-item label="过磅称重" prop="crossWeight">
		          <el-input v-model="form.crossWeight" placeholder="请输入过磅称重" />
		        </el-form-item>
       		</el-col>
	   </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-if="!isViewDisabled">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 详情dialog-->
    <el-dialog :visible.sync="detailOpen" width="50%" append-to-body :close-on-click-modal="false">
       <el-descriptions class="margin-top" title="卡口补录列详情" :column="3"  border>
		 <el-descriptions-item>
		        <template slot="label">
		         父id
		        </template>
		       {{form.hId}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         业务id
		        </template>
		       {{form.seqNo}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         IC卡号
		        </template>
		       {{form.icCard}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         车牌号
		        </template>
		       {{form.veNo}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         运管编码
		        </template>
		       {{form.transportId}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         箱号
		        </template>
		       {{form.contaId}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         rfid
		        </template>
		       {{form.rfid}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         ${column.columnComment}
		        </template>
		       {{form.veNoPosition}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         申请进出场
		        </template>
		       {{form.iEType}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         载重类型
		        </template>
		       {{form.veCrossType}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         核销状态
		        </template>
		       {{form.veBillStatus}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         通道代码
		        </template>
		       {{form.channelCode}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         通道名称
		        </template>
		       {{form.channelName}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         车辆自重
		        </template>
		       {{form.veSelfWeight}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         过磅称重
		        </template>
		       {{form.crossWeight}}
		  </el-descriptions-item>
         </el-descriptions>  
        <div slot="footer" class="dialog-footer" style="text-align: center;">
          <el-button @click="closeDetail">关闭</el-button>
        </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPassGateRecordList, getPassGateRecordList, delPassGateRecordList, addPassGateRecordList, updatePassGateRecordList, exportPassGateRecordList } from "@/api/kmwlpts/passGateRecordList";

export default {
  name: "PassGateRecordList",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
       //详情显示的时候，表单编辑禁用
      isViewDisabled:false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 卡口补录列表格数据
      passGateRecordListList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
       //显示详情
      detailOpen:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        hId: null,
        seqNo: null,
        icCard: null,
        veNo: null,
        transportId: null,
        contaId: null,
        rfid: null,
        veNoPosition: null,
        iEType: null,
        veCrossType: null,
        veBillStatus: null,
        channelCode: null,
        channelName: null,
        veSelfWeight: null,
        crossWeight: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        iEType: [
          { required: true, message: "申请进出场不能为空", trigger: "change" }
        ],
        veCrossType: [
          { required: true, message: "载重类型不能为空", trigger: "change" }
        ],
        channelCode: [
          { required: true, message: "通道代码不能为空", trigger: "blur" }
        ],
        channelName: [
          { required: true, message: "通道名称不能为空", trigger: "blur" }
        ],
        crossWeight: [
          { required: true, message: "过磅称重不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询卡口补录列列表 */
    getList() {
      this.loading = true;
      listPassGateRecordList(this.queryParams).then(response => {
        this.passGateRecordListList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        hId: null,
        seqNo: null,
        icCard: null,
        veNo: null,
        transportId: null,
        contaId: null,
        rfid: null,
        veNoPosition: null,
        iEType: null,
        veCrossType: null,
        veBillStatus: "0",
        channelCode: null,
        channelName: null,
        veSelfWeight: null,
        crossWeight: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.isViewDisabled=false;
      this.open = true;
      this.title = "添加卡口补录列";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      this.load(id);
      this.title = "修改卡口补录列";
      this.open = true;
    },
    //关闭详情
    closeDetail(){
      this.detailOpen=false;
    },
     //显示详情
    showDetail(row, column, event){
        this.reset();
        //关闭表单编辑模式
        this.isViewDisabled=true;
        const id = row.id;
        this.load(id);
          //打开详情
        this.detailOpen=true;
    },
     /** 加载数据 */
    load(id){
	    getPassGateRecordList(id).then(response => {
          this.form = response.data;
                  });
	},
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePassGateRecordList(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPassGateRecordList(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除卡口补录列编号为"' + ids + '"的数据项？').then(function() {
        return delPassGateRecordList(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有卡口补录列数据项？').then(() => {
        this.exportLoading = true;
        return exportPassGateRecordList(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
